Skip to content

refactor: build editor image lists with one library scanner - #341

Merged
TheWitness merged 10 commits into
developfrom
refactor/editor-image-list
Nov 11, 2026
Merged

TheWitness merged 10 commits into
developfrom
refactor/editor-image-list

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes #340

Stacked on #336, so merge #336 first. This PR targets #336's branch until then.

One scanner, wm_asset_library_images(), now builds the editor image lists. It returns entries shaped {kind, name, url, path}, under one set of rules: a readable regular file, with a png/gif/jpe?g extension and PNG/JPEG/GIF content. get_imagelist(), wm_asset_image_list() and the editor selectors all use it.

  • The selectors now send the same encoded images/ URL as the library dialog in data-imagesrc, so the server and wmEditorImageSrc() share one contract. Option values and their order are unchanged, and map images outside the library keep their value.
  • Symlinked images stay selectable but stay out of library management, as Implement separate icon and background image libraries #303 intended.
  • Stricter rules: a name ending in a newline is rejected, and a file named 0 no longer ends the scan early. Backgrounds now list in filename order instead of directory order.
  • Updates refactor(editor): render option lists through an escaping helper #336's E2E test to expect the encoded preview URL.
  • Tests: unit tests for each rule, and a PHP→jsdom fixture test that runs the real wmEditorImageSrc() and wmNodeIconPicker().
  • Verified: the full Pest suite passes (414), and all browser tests pass apart from ClickableHoverTest, which already fails on develop and is fixed in ci: run the jsdom browser tests with locked dependencies #333.

Interaction: #347 splits js/editor.js, and EditorImageOptionsTest.cjs here slices editor.js for wmEditorImageSrc(). Whichever of the two merges second needs that test switched to the shared loader.

Add wm_editor_attributes() and wm_editor_option() so every attribute value
and option label on the editor page is escaped by construction. Attribute
names must match a plain HTML name; true renders a boolean attribute and
false or null omits it.

Values use plugin_weathermap_escape_attr(), which double-encodes, so names
such as "A&B.png" round-trip instead of collapsing to "A&B.png".

Convert the icon, background, graph template, background sizing and key
style lists, and get_fontlist(). The key style labels were previously
printed unescaped, and the "Special Icon (AICON)" placeholder lost a
stray ">".

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ge lists

Fail when the editor page concatenates or interpolates an unescaped value
into an HTML attribute, or prints an <option> without wm_editor_option().

Render the icon and background lists from real image files with hostile
names through the editor page's own code, parse the result with
DOMDocument, and check that no attributes or elements are injected and
that every value and label round-trips.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
get_imagelist() and wm_asset_image_list() each scanned images/objects
and images/backgrounds with slightly different rules. Both now use
wm_asset_library_images(), which returns {kind, name, url, path} entries
under one set of acceptance rules: a readable regular file named
.png/.gif/.jpg/.jpeg whose content is a PNG, JPEG or GIF raster.

Symlinked files and libraries stay selectable in the editor but are
flagged unmanaged, so the image library dialog still refuses to list,
delete or overwrite them, as before.

The editor page builds its selectors with wm_editor_image_options() and
renders each entry through wm_editor_image_option(), a thin wrapper over
wm_editor_option(), so data-imagesrc carries the same encoded images/ URL
the library dialog sends to wmEditorImageSrc(). The hostile-filename E2E
test now expects that encoded URL and the entry list shape. Map images
outside the library keep their value; only images/ paths get a preview.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The PHP E2E test renders the icon and background selectors from a
temporary images tree through the editor's own helpers and compares
the result with a committed fixture. The browser test loads that
fixture into jsdom and checks every preview URL through the real
wmEditorImageSrc() and wmNodeIconPicker().

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The option lists now pass __() text to the escaping helper instead of
__esc(), so the template's source references change. Regenerating also
adds strings the template was already missing.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Write each extracted section to a temporary file and include it in the
caller's scope, as the page runs it, instead of passing it to eval().

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
… into refactor/editor-image-list

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

# Conflicts:
#	tests/E2E/EditorImageOptionListsTest.php
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@alcatron

alcatron commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Tested a899fab with its #336 dependency: 415 PHP tests passed. The image-options browser test also passes on this branch.

I reproduced the interaction you mentioned with #347: once both are merged, EditorImageOptionsTest.cjs fails with w.wmEditorImageSrc is not a function, because it still slices that function out of editor.js. Switching that test to the shared loadEditorScripts helper with editor.js and editor.picker.js fixed it locally. All 33 browser test files then passed in the combined checkout, which also included #333.

Worth making that adjustment in whichever PR merges second. The image-picker changes can share a focused real-browser check with #347 once combined.

Slicing wmEditorImageSrc() out of editor.js breaks once the editor script
is split into separate files. Evaluating every editor script the page
includes keeps the check independent of which file declares it.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof

Copy link
Copy Markdown
Member Author

EditorImageOptionsTest now evaluates every editor script the page includes instead of slicing wmEditorImageSrc() out of editor.js (8c78232), so it passes with or without the #347 split, whichever merges first. With #347 and #333 combined, all 32 browser test files pass.

I also did the real-browser check in Safari 27.2 against Cacti 1.2.32 with #336, #341, #347 and #333 combined: all 97 icon previews load, search filters the list, choosing an icon sets the field, closes the picker and returns focus to it, and Escape closes the picker without closing the node dialog. No JavaScript errors.

@alcatron alcatron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked 8c78232. The image-options test now works with the #347 split without our local workaround. All 33 browser test files pass in the combined batch, along with 648 PHP tests. Thanks for the Safari picker checks. Good from my side; merge after #336.

Base automatically changed from refactor/editor-option-escaping to develop November 11, 2026 01:40
…age-list

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit dc1fbb6 into develop Nov 11, 2026
10 checks passed
@TheWitness
TheWitness deleted the refactor/editor-image-list branch November 11, 2026 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor image lists are built in two places with different rules

5 participants